UserActivationPortlet = Class.extend(
		{
			init : function() {
				this.name = "UserActivationPortlet";
				this.model = {};
				this.isLogin = false;
				this.registerObserver();
			},
			
			onBegin: function(){
				this.action = this.getRequest().getParam('action');
			},
			
			run : function() {
				this.getPortletPlaceholder().paintCanvas(tmpl("UserActivationPorletView",{}));
				var _this = this;
				var isErrorFound = false;
				if(this.action == "activate"){
					this.username = this.getRequest().getParam('username');
					this.code = this.getRequest().getParam('code');
					$("#userActivationMain").empty();
					this.onAjax('ajax', 'activation', {username: this.username, code: this.code}, 'POST', {
						'onSuccess': function(ret){
							if(ret.code == 1){
								$("#userActivationMain").append(tmpl("UserActivationActivate",{}));
							} else if (ret.code == 2){
								$("#userActivationMain").append(tmpl("UserActivationExpired",{}));
							} else if (ret.code == 3){
								$("#userActivationMain").append(tmpl("UserActivationInvalid",{}));
							} else if (ret.code == 4){
								$("#userActivationMain").append(tmpl("UserActivationTwice",{}));
							} else {
								isErrorFound = true;
							}
						},
						'onFailure': function(msg)	{
							isErrorFound = true;
						}
					});
				} else if (this.action == "reactivate"){
					this.checkUserLogin();
					if(!this.isLogin){
						console.log("not loggin");
						return;
					}
					this.onAjax('user-ajax', 're-activate', {}, 'POST', {
						'onSuccess': function(ret){
							if(ret == true){
								$("#userActivationMain").empty().append(tmpl("UserActivationSent",{}));
							} else {
								isErrorFound = true;
							}
						},
						'onFailure': function(msg)	{
							isErrorFound = true;
						}
					});
				} else {
					isErrorFound = true;
				}
				
				if(isErrorFound){
					var subject = SingletonFactory.getInstance(Subject);
					var request = new Request("ErrorPage","",{"code":"888", "msg":"Lỗi","content":"Đã có lỗi xảy ra"});
					subject.notifyEvent('RequestRoute', request);
					return;
				}
			},
			
			checkUserLogin : function() {
				var sbj = SingletonFactory.getInstance(Subject);
				sbj.notifyEvent("NeedLogin", {});
			},

			onLoginSuccess : function(eventData) {
				this.isLogin = true;
			},
			
			onReloadPage: function(){
				this.onBegin();
				this.run();
			},
			
			onEnd: function()	{
				this.unregisterObserver();
			}
		}).implement(PortletInterface).implement(RenderInterface).implement(ObserverInterface).implement(AjaxInterface);